package com.skyable.auth.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.skyable.auth.entity.SysUser;
import com.skyable.auth.mapper.UserMapper;
import com.skyable.auth.service.IUserService;
import com.skyable.common.common.ServiceResult;
import org.springframework.stereotype.Service;

/**
 * @author GaoYuan
 * @title: UserServiceImpl
 * @projectName spring-cloud-demo
 * @description: TODO
 * @date 2021/4/613:11
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper,SysUser> implements IUserService {
    @Override
    public ServiceResult<SysUser> createUser(SysUser sysUser) {
        ServiceResult<SysUser> serviceResult = new ServiceResult<>();
        baseMapper.insert(sysUser);
        serviceResult.setResult(sysUser);
        return serviceResult;
    }

    @Override
    public ServiceResult<SysUser> getUserByUserName(String username) {
        ServiceResult<SysUser> serviceResult = new ServiceResult<>();
        SysUser sysUser = lambdaQuery().eq(SysUser::getUsername, username).one();
        serviceResult.setResult(sysUser);
        return serviceResult;
    }

    @Override
    public ServiceResult<SysUser> getUserByPhoneNum(String phone) {
        ServiceResult<SysUser> serviceResult = new ServiceResult<>();
        SysUser sysUser = lambdaQuery().eq(SysUser::getPhone, phone).one();
        serviceResult.setResult(sysUser);
        return serviceResult;
    }
}
